<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>MySQL Functions (PDO_MYSQL)</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.pdo-informix.connection.html">PDO_INFORMIX DSN</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.pdo-mysql.connection.html">PDO_MYSQL DSN</a></div>
 <div class="up"><a href="pdo.drivers.html">PDO 驱动</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="ref.pdo-mysql" class="reference">
  
  <h1 class="title">MySQL Functions (PDO_MYSQL)</h1>
  
  <div class="partintro">

   <div class="section" id="pdo-mysql.intro">
   <h2 class="title">简介</h2>
    <p class="para">
     PDO_MYSQL is a driver that implements the <a href="intro.pdo.html" class="link">PHP
     Data Objects (PDO) interface</a>
     to enable access from PHP to MySQL 3.x, 4.x and 5.x databases.
    </p>
    <p class="para">
     PDO_MYSQL will take advantage of native prepared statement support
     present in MySQL 4.1 and higher.  If you&#039;re using an older version of the
     mysql client libraries, PDO will emulate them for you.
    </p>
    <div class="warning"><strong class="warning">Warning</strong>
     <p class="para">
      Beware: Some MySQL table types (storage engines) do not support transactions.  When
      writing transactional database code using a table type that does not support
      transactions, MySQL will pretend that a transaction was initiated successfully.
      In addition, any DDL queries issued will implicitly
      commit any pending transactions.
     </p>
    </div>
   </div>
   

<div class="section" id="ref.pdo-mysql.installation">
 <h2 class="title">安装</h2>
 <p class="para">
  Use <strong class="option configure">--with-pdo-mysql[=DIR]</strong>
 to install
  the PDO MySQL extension, where the optional <em>[=DIR]</em>
  is the MySQL base install directory. If <a href="book.mysqlnd.html" class="link">mysqlnd</a>
  is passed as <em>[=DIR]</em>, then the MySQL native driver will be used.
 </p>
 <p class="para">
  Optionally, the <strong class="option configure">--with-mysql-sock[=DIR]</strong>
 sets to location
  to the MySQL unix socket pointer for all MySQL extensions, including PDO_MYSQL. If
  unspecified, the default locations are searched.
 </p>
 <p class="para">
  Optionally, the <strong class="option configure">--with-zlib-dir[=DIR]</strong>
 is used to set
  the path to the libz install prefix.
 </p>
 <p class="para">
  <div class="example-contents screen">
<div class="cdata"><pre>
$ ./configure --with-pdo-mysql --with-mysql-sock=/var/mysql/mysql.sock
</pre></div>
  </div>
 </p>
 <p class="para">
  SSL support is enabled using the appropriate <a href="ref.pdo-mysql.html#pdo-mysql.constants" class="link">PDO_MySQL constants</a>,
  which is equivalent to calling the <a href="http://dev.mysql.com/doc/mysql/en/mysql-ssl-set.html" class="link external">&raquo;&nbsp;MySQL C API function mysql_ssl_set()</a>.
  Also, SSL cannot be enabled with <strong class="classname">PDO::setAttribute</strong> because the connection
  already exists. See also the MySQL documentation about <a href="http://dev.mysql.com/doc/mysql/en/configuring-for-ssl.html" class="link external">&raquo;&nbsp;connecting to
  MySQL with SSL</a>.
 </p>

 <table class="doctable table">
  <caption><strong>更新日志</strong></caption>
  
   <thead>
    <tr>
     <th>版本</th>
     <th>说明</th>
    </tr>

   </thead>

   <tbody class="tbody">
    <tr>
     <td>5.4.0</td>
     <td>
      MySQL client libraries 4.1 and below are no longer supported.
     </td>
    </tr>

    <tr>
     <td>5.3.9</td>
     <td>
      Added SSL support with mysqlnd and OpenSSL.
     </td>
    </tr>

    <tr>
     <td>5.3.7</td>
     <td>
      Added SSL support with libmysqlclient and OpenSSL.
     </td>
    </tr>

   </tbody>
  
 </table>


</div>



   

<div class="section" id="pdo-mysql.constants">
 <h2 class="title">预定义常量</h2>
 <p class="simpara">下列常量由此驱动定义，且仅在扩展编译入 PHP
或在运行时动态载入时可用。另外，使用此驱动时，仅会使用这些驱动特定的常量。使用其他驱动的驱动特定的常量可能会导致不可预见的情况。如果代码可运行于多个驱动，<span class="function"><a href="pdo.getattribute.html" class="function">PDO::getAttribute()</a></span>
可被用于获取
<strong><code>PDO_ATTR_DRIVER_NAME</code></strong>
属性以检查驱动。</p>
 <dl>

  
   <dt id="pdo.constants.mysql-attr-use-buffered-query">
    <strong><code>PDO::MYSQL_ATTR_USE_BUFFERED_QUERY</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <span class="simpara">
     If this attribute is set to <strong><code>TRUE</code></strong> on a
     <a href="class.pdostatement.html" class="classname">PDOStatement</a>, the MySQL driver will use the
     buffered versions of the MySQL API.  If you&#039;re writing portable code, you
     should use <span class="function"><a href="pdostatement.fetchall.html" class="function">PDOStatement::fetchAll()</a></span> instead.
    </span>
    <p class="para">
     <div class="example" id="example-951"><p><strong>Example #1 Forcing queries to be buffered in mysql</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">ATTR_DRIVER_NAME</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #DD0000">'mysql'</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'select&nbsp;*&nbsp;from&nbsp;foo'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">MYSQL_ATTR_USE_BUFFERED_QUERY&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">"my&nbsp;application&nbsp;only&nbsp;works&nbsp;with&nbsp;mysql;&nbsp;I&nbsp;should&nbsp;use&nbsp;\$stmt-&gt;fetchAll()&nbsp;instead"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

     </div>
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-local-infile">
    <strong><code>PDO::MYSQL_ATTR_LOCAL_INFILE</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Enable <em>LOAD LOCAL INFILE</em>.
    </p>
    <p class="para">
     Note, this constant can only be used in the <em><code class="parameter">driver_options</code></em> 
     array when constructing a new database handle.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-init-command">
    <strong><code>PDO::MYSQL_ATTR_INIT_COMMAND</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Command to execute when connecting to the MySQL server. Will
     automatically be re-executed when reconnecting.
    </p>
    <p class="para">
     Note, this constant can only be used in the <em><code class="parameter">driver_options</code></em> 
     array when constructing a new database handle.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-read-default-file">
    <strong><code>PDO::MYSQL_ATTR_READ_DEFAULT_FILE</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Read options from the named option file instead of from
     <var class="filename">my.cnf</var>. This option is not available if 
     mysqlnd is used, because mysqlnd does not read the mysql 
     configuration files.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-read-default-group">
    <strong><code>PDO::MYSQL_ATTR_READ_DEFAULT_GROUP</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Read options from the named group from <var class="filename">my.cnf</var> or the
     file specified with <strong><code>MYSQL_READ_DEFAULT_FILE</code></strong>. This option 
     is not available if mysqlnd is used, because mysqlnd does not read the mysql 
     configuration files.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-max-buffer-size">
    <strong><code>PDO::MYSQL_ATTR_MAX_BUFFER_SIZE</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Maximum buffer size. Defaults to 1 MiB. This constant is not supported when 
     compiled against mysqlnd.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-direct-query">
    <strong><code>PDO::MYSQL_ATTR_DIRECT_QUERY</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Perform direct queries, don&#039;t use prepared statements.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-found-rows">
    <strong><code>PDO::MYSQL_ATTR_FOUND_ROWS</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Return the number of found (matched) rows, not the 
     number of changed rows.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-ignore-space">
    <strong><code>PDO::MYSQL_ATTR_IGNORE_SPACE</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Permit spaces after function names. Makes all functions 
     names reserved words.
    </p>
   </dd>

  
  
   <dt id="pdo.constants.mysql-attr-compress">
    <strong><code>PDO::MYSQL_ATTR_COMPRESS</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     Enable network communication compression. This is not supported when 
     compiled against mysqlnd.
    </p>
   </dd>

  

  
   <dt id="pdo.constants.mysql-attr-ssl-ca">
    <strong><code>PDO::MYSQL_ATTR_SSL_CA</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     The file path to the SSL certificate authority.
    </p>
    <p class="para">
     自以下版本起 PHP  5.3.7.
    </p>
   </dd>

  

  
   <dt id="pdo.constants.mysql-attr-ssl-capath">
    <strong><code>PDO::MYSQL_ATTR_SSL_CAPATH</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     The file path to the directory that contains the trusted SSL
     CA certificates, which are stored in PEM format.
    </p>
    <p class="para">
     自以下版本起 PHP  5.3.7.
    </p>
   </dd>

  

  
   <dt id="pdo.constants.mysql-attr-ssl-cert">
    <strong><code>PDO::MYSQL_ATTR_SSL_CERT</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     The file path to the SSL certificate.
    </p>
    <p class="para">
     自以下版本起 PHP  5.3.7.
    </p>
   </dd>

  

  
   <dt id="pdo.constants.mysql-attr-cipher">
    <strong><code>PDO::MYSQL_ATTR_SSL_CIPHER</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     A list of one or more permissible ciphers to use for SSL encryption, in a format
     understood by OpenSSL. For example: <em>DHE-RSA-AES256-SHA:AES128-SHA</em>
    </p>
    <p class="para">
     自以下版本起 PHP  5.3.7.
    </p>
   </dd>

  

  
   <dt id="pdo.constants.mysql-attr-key">
    <strong><code>PDO::MYSQL_ATTR_SSL_KEY</code></strong>
     (<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
   </dt>

   <dd>

    <p class="para">
     The file path to the SSL key.
    </p>
    <p class="para">
     自以下版本起 PHP  5.3.7.
    </p>
   </dd>

  

 </dl>

</div>



   

<div class="section" id="pdo-mysql.configuration">
 <h2 class="title">运行时配置</h2>
 <p class="simpara">
这些函数的行为受 <var class="filename">php.ini</var> 中的设置影响。
</p>
 <p class="para">
  <table class="doctable table">
   <caption><strong>PDO_MYSQL Configuration Options</strong></caption>
   
    <thead>
     <tr>
      <th>名字</th>
      <th>默认</th>
      <th>可修改范围</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td><a href="ref.pdo-mysql.html#ini.pdo-mysql.default-socket" class="link">pdo_mysql.default_socket</a></td>
      <td>&quot;/tmp/mysql.sock&quot;</td>
      <td>PHP_INI_SYSTEM</td>
     </tr>

     <tr>
      <td><a href="ref.pdo-mysql.html#ini.pdo-mysql.debug" class="link">pdo_mysql.debug</a></td>
      <td>NULL</td>
      <td>PHP_INI_SYSTEM</td>
     </tr>

    </tbody>
   
  </table>

  有关 PHP_INI_* 样式的更多详情与定义，见 <a href="configuration.changes.modes.html" class="xref">配置可被设定范围</a>。
 </p>

 <p class="para">这是配置指令的简短说明。</p>

 <p class="para">
  <dl>

   
    <dt id="ini.pdo-mysql.default-socket">
     <em><code class="parameter">pdo_mysql.default_socket</code></em>
     <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
    </dt>

    <dd>

     <p class="para">
      Sets a Unix domain socket. This value can either be set at compile time if 
      a domain socket is found at configure. This ini setting is Unix only.
     </p>
    </dd>

   
   
    <dt id="ini.pdo-mysql.debug">
     <em><code class="parameter">pdo_mysql.debug</code></em>
     <span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span>
    </dt>

    <dd>

     <p class="para">
      Enables debugging for PDO_MYSQL. This setting is only available when PDO_MYSQL is 
      compiled against mysqlnd and in PDO debug mode.
     </p>
    </dd>

   
  </dl>

 </p>
</div>



  </div>

  

 <h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="ref.pdo-mysql.connection.html">PDO_MYSQL DSN</a> — Connecting to MySQL databases</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.pdo-informix.connection.html">PDO_INFORMIX DSN</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.pdo-mysql.connection.html">PDO_MYSQL DSN</a></div>
 <div class="up"><a href="pdo.drivers.html">PDO 驱动</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
